/**
 * Created by cj on 2017/5/2.
 */

var mySingleton = (function () {
    var instance;
    function init() {
        //单例
        //私有方法和变量
        function privateMethod() {
            console.log("I am private");
        }
        var privateVariable = "I am also private";
        var privateRandomNumber = Math.random();
        return {
            //公共方法和变量
            publicMethod:function () {
                console.log("The public can see me!");
            },
            publicProperty:"I am also public",
            getRandomNumber:function () {
                return privateRandomNumber;
            }
        };
    };
    return {
        //如果存在获取此单例实例，如果不存在创建一个单例实例
        getInstance:function () {
            if(!instance){
                instance=init();
            }
            return instance;
        }
    };
})();